﻿jQuery.fn.extend(
{
    OpenDiv: function(setting) {
        var options = { left: 0, top: 0, opacity: 0.7, ceiling: "ceiling" };
        $.extend(options, setting);
        var sWidth, sHeight;
        sWidth = window.screen.availWidth;
        if (window.screen.availHeight > document.body.scrollHeight) {
            sHeight = window.screen.availHeight;

        } else {
            sHeight = document.body.scrollHeight + 20;
        }

        $("#background").show();
        var MyDiv_w = this.width();
        var MyDiv_h = this.height();
        MyDiv_w = parseInt(MyDiv_w);
        MyDiv_h = parseInt(MyDiv_h);
        var width = $.PageSize().Width;
        var height = $.PageSize().Height;
        var left = $.ScrollPosition().Left;
        var top = $.ScrollPosition().Top;
        var Div_topposition = options.top;
        var Div_leftposition = options.left;
        var ceiling = $("#" + options.ceiling);
        if (Div_topposition == 0) {
            if (ceiling.length == 1) {
                Div_topposition = ceiling.offset().top + ceiling.height();
            }
            else {
                Div_topposition = top + (height / 2) - (MyDiv_h / 2);
            }
        }
        if (Div_leftposition == 0) {
            if (ceiling.length == 1) {
                Div_leftposition = ceiling.offset().left;
            }
            else {
                Div_leftposition = left + (width / 2) - (MyDiv_w / 2);
            }
        }

        if (Div_leftposition + MyDiv_w > width) {
            Div_leftposition = width - MyDiv_w;
        }
        if (Div_topposition + MyDiv_h > height) {
            Div_topposition = height - MyDiv_h;
        }

        this.css("position", "fixed");
        this.css("z-index", "10001");
        this.css("background", "#fff");
        this.css("left", Div_leftposition + "px");
        this.css("top", Div_topposition + "px");
        this.css("width", "200px");
        if ($.browser.mozilla) {
            this.show();
            return;
        }
        this.fadeIn("fast");

    },
    CloseDiv: function() {

        if ($.browser.mozilla) {
            this.hide();

        } else {
            this.fadeOut("fast");
        }

        $("#background").hide();

    }

});
$.extend(
{
    PageSize: function() {
        var width = 0;
        var height = 0;
        width = window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
        height = window.innerHeight != null ? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null ? document.body.clientHeight : null;
        return { Width: width, Height: height };
    }
    , ScrollPosition: function() {
        var top = 0, left = 0;
        if ($.browser.mozilla) {
            top = window.pageYOffset;
            left = window.pageXOffset;

        }
        else if ($.browser.msie) {
            top = document.documentElement.scrollTop;
            left = document.documentElement.scrollLeft;

        }
        else if (document.body) {
            top = document.body.scrollTop;
            left = document.body.scrollLeft;
        }
        return { Top: top, Left: left };

    }
});
